﻿Imports System
Imports System.CodeDom
Imports System.Reflection

Namespace System.Workflow.ComponentModel.Compiler
    Friend NotInheritable Class DesignTimeParameterInfo
        Inherits ParameterInfo
        ' Methods
        Friend Sub New(ByVal codeParameterType As CodeTypeReference, ByVal member As MemberInfo)
            MyBase.MemberImpl = member
            MyBase.NameImpl = Nothing
            Me.codeParameterType = codeParameterType
            MyBase.AttrsImpl = ParameterAttributes.None
            MyBase.PositionImpl = -1
        End Sub

        Friend Sub New(ByVal codeParameter As CodeParameterDeclarationExpression, ByVal position As Integer, ByVal member As MemberInfo)
            MyBase.MemberImpl = member
            MyBase.NameImpl = Helper.EnsureTypeName(codeParameter.Name)
            Me.codeParameterType = codeParameter.Type
            MyBase.AttrsImpl = Helper.ConvertToParameterAttributes(codeParameter.Direction)
            Me.isRef = (codeParameter.Direction = FieldDirection.Ref)
            MyBase.PositionImpl = position
        End Sub


        ' Properties
        Public Overrides ReadOnly Property ParameterType As Type
            Get
                Dim typeNameFromCodeTypeReference As String = DesignTimeType.GetTypeNameFromCodeTypeReference(Me.codeParameterType, [TryCast](Me.Member.DeclaringType,DesignTimeType))
                If (((MyBase.AttrsImpl And ParameterAttributes.Out) > ParameterAttributes.None) OrElse Me.isRef) Then
                    typeNameFromCodeTypeReference = (typeNameFromCodeTypeReference & "&"c)
                End If
                MyBase.ClassImpl = [TryCast](Me.Member.DeclaringType,DesignTimeType).ResolveType(typeNameFromCodeTypeReference)
                Return MyBase.ParameterType
            End Get
        End Property


        ' Fields
        Private codeParameterType As CodeTypeReference
        Private isRef As Boolean
    End Class
End Namespace

